import 'package:flutter/material.dart';
import 'package:flutter_ahj_app/app/yhpc/YhpcViewModel.dart';
import 'package:flutter_ahj_app/base/basewidget/view/BaseWidget.dart';
import 'package:flutter_ahj_app/base/utils/JUIKit/JText.dart';
import 'package:flutter_ahj_app/base/utils/ToastUtils.dart';
import 'package:flutter_ahj_app/base/utils/mTopBar.dart';
import 'package:flutter_ahj_app/base/values/SQColor.dart';
import 'package:flutter_ahj_app/base/values/dimens.dart';
import 'package:flutter_ahj_app/base/widget/LoadingWidget.dart';
import 'package:flutter_ahj_app/base/widget/NoneData.dart';

class ChoosePclx extends BaseStatefulWidget {
  @override
  State<StatefulWidget> initState() {
    // TODO: implement initState
    // throw UnimplementedError();
    return ChoosePclxState();
  }
}

class ChoosePclxState extends BaseState<YhpcViewModel, ChoosePclx> {
  List _list;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    Future.delayed(Duration.zero, () {
      _getData();
    });
  }

  @override
  Widget initWidget() {
    return Scaffold(
      backgroundColor: SQColor.white,
      appBar: MTopBar(
        elevation: 0,
        title: '选择排查类型',
      ).create(),
      body: _list == null ? LoadingWidget() : _list.length == 0 ? NoneData() : _bodyView(),
    );
  }

  _getData() {
    viewModel.getPclx();
    viewModel.getPclxDataStream().listen((event) {
      if (event['code'] == '0') {
        setState(() {
          _list = [];
          _list = event['data'];
        });
      } else {
        ToastUtils.showToast(event['msg']);
      }
    }, onError: (e) {
      print(e);
    });
  }

  _bodyView() {
    return Container(
      margin: EdgeInsets.all(15),
      child: Container(
        child: SingleChildScrollView(
          child: ListView.builder(
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemCount: _list.length,
              itemBuilder: (context, index) {
                return InkWell(
                  onTap: () {
                    Navigator.pop(context, _list[index]);
                  },
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.only(top: 15, bottom: 15),
                        child: Row(
                          children: [
                            Expanded(
                              child: JText(_list[index]['typeName'] ?? ''),
                            ),
                            Icon(
                              Icons.arrow_forward_ios_outlined,
                              size: Dimens.dimens15,
                              color: SQColor.black_999999,
                            ),
                          ],
                        ),
                      ),
                      Container(
                        height: 1,
                        color: Color(0xfff6f6f6),
                        width: double.infinity,
                      ),
                    ],
                  ),
                );
              }),
        ),
      ),
    );
  }
}
